package com.yeeKa.common.exception;


import com.yeeKa.enums.StatusCode;
import com.yeeKa.utils.StringUtils;

/**
 * @author win10
 */
public class ExceptionCast {

    /**
     * 抛出自定义异常
     */
    public static void assertNullInteger(Integer code, String message) {
        throw new BusinessException(code, message);
    }

    public static void assertNullString(String str, String message) {
        if (StringUtils.isEmpty(str)) {
            assertNullInteger(StatusCode.PARAM_REQUIRE.getCode(), message);
        }
    }

    public static void assertNullInteger(String[] str, String message) {
        if (StringUtils.isEmpty(str)) {
            assertNullInteger(StatusCode.PARAM_REQUIRE.getCode(), message);
        }
    }

    public static void assertNullSize(Integer size, String message) {
        if (size == 0) {
            assertNullInteger(StatusCode.PARAM_REQUIRE.getCode(), message);
        }
    }

    public static void assertBoolean(Boolean b, String message) {
        if (b) {
            assertNullInteger(StatusCode.PARAM_REQUIRE.getCode(), message);
        }
    }

    public static void assertNullObject(Object object, int code, String message) {
        if (StringUtils.isNull(object)) {
            assertNullInteger(code, message);
        }
    }
}
